#!/usr/bin/python
# -*- coding: utf-8 -*-
from forms import *
def save_new_role(user, form_data):

    user.save()
    department_id = form_data.cleaned_data['department']
    department = Department.objects.get(id = department_id)
    role_type = form_data.cleaned_data['role_type']
    research_domain = form_data.cleaned_data['research_domain']
    if isinstance(form_data, StudentRoleForm):
        admission_year = form_data.cleaned_data['admission_year']
        student = Student(user = user, department = department,
                          role_type = role_type,
                          admission_year = admission_year,
                          research_domain = research_domain)
        student.save()
    else:
        teacher = Teacher(user = user, department = department,
                          role_type = role_type,
                          research_domain = research_domain)
        teacher.save()
